package jp.ac.segakuen;

import java.util.List;

import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;

public class OpenCampassMenuTableUtil {
	public static String insertNew(String dateid,String menustring) {
		OpenCampassMenuTable ocmt = new OpenCampassMenuTable(dateid,menustring);
    	PersistenceManager pm = PMF.get().getPersistenceManager();
    	try{
    		pm.makePersistentAll(ocmt);
    	}finally{
    		pm.close();
    	}

		return ocmt.getId().toString();
	}
	
	@SuppressWarnings("unchecked")
	public static void deleteByDateName(String omid){
	    PersistenceManager pm = PMF.get().getPersistenceManager();
	    Query query = pm.newQuery(OpenCampassMenuTable.class);
	    query.setFilter("ocMenuId == omid");
	    query.declareParameters("String omid");
	    try {
	    	List<OpenCampassMenuTable> results = (List<OpenCampassMenuTable>)query.execute(omid);
   		    if(results.iterator().hasNext()){
		    	for(OpenCampassMenuTable ocmt : results){
		    		pm.deletePersistent(ocmt);
		    	}
		    }
	    } catch (JDOObjectNotFoundException e) {
		        System.out.println(e);
		        return;
	    } finally {
		    	pm.close();
	    }		
	}
	

	public static void deleteByDateId(String omid){
	    PersistenceManager pm = PMF.get().getPersistenceManager();
	    try{
	    	OpenCampassMenuTable ocmt = pm.getObjectById(OpenCampassMenuTable.class,Long.valueOf(omid));
	    	pm.deletePersistent(ocmt);
	    } catch (JDOObjectNotFoundException e) {
		        System.out.println(e);
		        return;
	    } finally {
		    	pm.close();
	    }		
	}
	
	
	
}
